import { Conversation } from '@tencentcloud/chat'
import { useTencentMessageStore } from '@/stores/tencentMessageStore.ts'
import { useTencentConversationStore } from '@/stores/tencentConversationStore.ts'
import { useMitt } from '@/hooks/useMitt.ts'
import { MittEnum } from '@/enums'

export const useTencentConversation = () => {
  const tencentMessageStore = useTencentMessageStore()
  const tencentConversationStore = useTencentConversationStore()

  const handleConvClick = async (item: Conversation) => {
    if (item.conversationID === tencentConversationStore.currentConv.conversationID) {
      return
    }

    await tencentConversationStore.getConversationProfile(item.conversationID)

    // 更新当前会话信息
    useMitt.emit(MittEnum.MSG_BOX_SHOW, { msgBoxShow: true })

    tencentMessageStore.getMessageList({ conversationID: item.conversationID })
    tencentConversationStore.setMessageRead(item.conversationID)
  }

  return {
    handleConvClick
  }
}
